package com.easy.persondemo;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.easylib.base.BaseActivity;
import com.easylib.utils.ImageLoadUtils;
import com.guyj.CommonAdapter;
import com.guyj.base.ViewHolder;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class InfoActivity extends BaseActivity {

    LinearLayoutManager llm, llmpdf;
    List<String> datas;
    @Bind(R.id.rv_info)
    RecyclerView tvInfo;
    @Bind(R.id.recycler)
    RecyclerView recycler;
    @Bind(R.id.ll_rv)
    LinearLayout ll_rv;

    @Override
    public int getContentViewId() {
        return R.layout.activity_info;
    }

    @Override
    protected void initView(Bundle savedInstanceState) {

    }

    @Override
    protected void initVariable() {
        llm = new LinearLayoutManager(mContext, LinearLayoutManager.HORIZONTAL, false);
        llmpdf = new LinearLayoutManager(mContext, LinearLayoutManager.VERTICAL, false);
        datas = new ArrayList<>();
        datas.add("邵某某");
        datas.add("朱某某");
        datas.add("朱三某");
        datas.add("朱三某");
        datas.add("朱三某");
        datas.add("朱三某");
        datas.add("朱三某");
        datas.add("朱三某");
        datas.add("朱三某");
        datas.add("朱三某");
        datas.add("朱三某");
        datas.add("朱三某");

    }

    @Override
    protected void processLogic(Bundle savedInstanceState) {
        recycler.setLayoutManager(llm);
        tvInfo.setLayoutManager(llmpdf);
        tvInfo.setAdapter(new CommonAdapter<String>(mContext, R.layout.item_pdf, datas) {
            @Override
            protected void convert(ViewHolder viewHolder, String o, int i) {
                viewHolder.setText(R.id.tv_pdf, 1 + i + "");
                switch (i) {
                    case 0:
                        ImageLoadUtils.into(R.drawable.a0001, (ImageView) viewHolder.getView(R.id.iv_pdf));
//                        ((ImageView) viewHolder.getView(R.id.iv_pdf)).setImageResource(R.drawable.a0001);
                        break;
                    case 1:
                        ImageLoadUtils.into(R.drawable.a0002, (ImageView) viewHolder.getView(R.id.iv_pdf));
//                        ((ImageView) viewHolder.getView(R.id.iv_pdf)).setImageResource(R.drawable.a0002);
                        break;
                    case 2:
                        ImageLoadUtils.into(R.drawable.a0003, (ImageView) viewHolder.getView(R.id.iv_pdf));
//                        ((ImageView) viewHolder.getView(R.id.iv_pdf)).setImageResource(R.drawable.a0003);
                        break;
                    case 3:
                        ImageLoadUtils.into(R.drawable.a0004, (ImageView) viewHolder.getView(R.id.iv_pdf));
//                        ((ImageView) viewHolder.getView(R.id.iv_pdf)).setImageResource(R.drawable.a0004);
                        break;
                    case 4:
                        ImageLoadUtils.into(R.drawable.a0005, (ImageView) viewHolder.getView(R.id.iv_pdf));
//                        ((ImageView) viewHolder.getView(R.id.iv_pdf)).setImageResource(R.drawable.a0005);
                        break;
                    case 5:
                        ImageLoadUtils.into(R.drawable.a0006, (ImageView) viewHolder.getView(R.id.iv_pdf));
//                        ((ImageView) viewHolder.getView(R.id.iv_pdf)).setImageResource(R.drawable.a0006);
                        break;
                    case 6:
                        ImageLoadUtils.into(R.drawable.a0007, (ImageView) viewHolder.getView(R.id.iv_pdf));
//                        ((ImageView) viewHolder.getView(R.id.iv_pdf)).setImageResource(R.drawable.a0007);
                        break;
                    case 7:
                        ImageLoadUtils.into(R.drawable.a0008, (ImageView) viewHolder.getView(R.id.iv_pdf));
                        ((ImageView) viewHolder.getView(R.id.iv_pdf)).setImageResource(R.drawable.a0008);
                        break;
                    case 8:
                        ImageLoadUtils.into(R.drawable.a0009, (ImageView) viewHolder.getView(R.id.iv_pdf));
//                        ((ImageView) viewHolder.getView(R.id.iv_pdf)).setImageResource(R.drawable.a0009);
                        break;
                    case 9:
                        ImageLoadUtils.into(R.drawable.a0010, (ImageView) viewHolder.getView(R.id.iv_pdf));
//                        ((ImageView) viewHolder.getView(R.id.iv_pdf)).setImageResource(R.drawable.a0010);
                        break;
                    case 10:
                        ImageLoadUtils.into(R.drawable.a0001, (ImageView) viewHolder.getView(R.id.iv_pdf));
//                        ((ImageView) viewHolder.getView(R.id.iv_pdf)).setImageResource(R.drawable.a0011);
                        break;
                    case 11:
                        ImageLoadUtils.into(R.drawable.a0012, (ImageView) viewHolder.getView(R.id.iv_pdf));
//                        ((ImageView) viewHolder.getView(R.id.iv_pdf)).setImageResource(R.drawable.a0012);
                        break;

                }
                viewHolder.setOnClickListener(R.id.iv_pdf, new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        if (ll_rv.getVisibility() == View.VISIBLE) {
                            ll_rv.setVisibility(View.GONE);
                        } else {
                            ll_rv.setVisibility(View.VISIBLE);
                        }
                    }
                });
            }
        });
        recycler.setAdapter(new CommonAdapter<String>(mContext, R.layout.item_head_name, datas) {
            @Override
            protected void convert(ViewHolder viewHolder, String o, final int i) {
                viewHolder.setText(R.id.tv_name, datas.get(i));
                switch (i) {
                    case 0:
                        ((ImageView) viewHolder.getView(R.id.iv_head)).setImageResource(R.drawable.head1);
                        break;
                    case 1:
                        ((ImageView) viewHolder.getView(R.id.iv_head)).setImageResource(R.drawable.head2);
                        break;
                    case 2:
                        ((ImageView) viewHolder.getView(R.id.iv_head)).setImageResource(R.drawable.head3);
                        break;
                }
                viewHolder.setOnClickListener(R.id.ll_root, new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        int pos = 0;
                        switch (i) {
                            case 0:
                                pos = 0;
                                break;
                            case 1:
                                pos = 4;
                                break;
                            case 2:
                                pos = 8;
                                break;
                        }
                        tvInfo.scrollToPosition(pos);
                    }
                });
            }
        });
    }


    @OnClick({R.id.tv_shouye, R.id.tv_yiti, R.id.activity_info, R.id.rv_info})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.activity_info:
                if (ll_rv.getVisibility() == View.VISIBLE) {
                    ll_rv.setVisibility(View.GONE);
                } else {
                    ll_rv.setVisibility(View.VISIBLE);
                }
                break;
            case R.id.tv_shouye:
                setResult(RESULT_OK, new Intent(mContext, MainActivity.class));
                finish();
                break;
            case R.id.tv_yiti:
                finish();
                break;
        }
    }
}
